package com.sxpi.chapter01;

import java.util.ArrayList;

/**
 * @Author: 董伟豪
 * @Date: 2023/2/6 14:05
 */
public class Client {

    /**
     * 可以得出他们共享的是一个空间的内存地址
     * 这个是一个潜拷贝，我p1并没有拷贝上
     * @param args
     * @throws CloneNotSupportedException
     */
    public static void main(String[] args) throws CloneNotSupportedException {
        // 本地对象
        Prototype p1 = new Prototype();
        p1.setName("飞哥");
        p1.setAddress(new Address("湖南","长沙"));

        Prototype p2 = (Prototype) p1.clone();
        p2.setName("yykk");
        p2.getAddress().setCity("漳州");

        System.out.println(p1.getName() + p1.getAddress().getCity());
        System.out.println(p2.getName() + p2.getAddress().getCity());



        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        ArrayList<Integer> arrayList2 = (ArrayList<Integer>)arrayList.clone();
        arrayList2.add(4);
        System.out.println(arrayList.size());
        System.out.println(arrayList2.size());
    }
}
